package easy;

public class Solution_812 {

    public double largestTriangleArea(int[][] points) {
        double max = 0.0;
        int length = points.length;
        for (int i = 0; i < length - 2; i++) {
            for (int j = i + 1; j < length - 1; j++) {
                for (int k = j; k < length; k++) {
                    boolean flag = true;
                    int sub_x1 = points[k][0] - points[j][0];
                    int sub_x2 = points[j][0] - points[i][0];
                    if (sub_x1 == 0 && sub_x2 == 0) {
                        flag = false;
                    }
                    if (sub_x1 != 0 && sub_x2 != 0) {
                        double k1 = (points[k][1] - points[j][1] - 0.0) / sub_x1;
                        double k2 = (points[j][1] - points[i][1] - 0.0) / sub_x2;
                        if (k1 == k2) {
                            flag = false;
                        }
                    }
                    if (flag) {
                        double aa = (points[k][0] - points[j][0]) * (points[k][0] - points[j][0])
                            + (points[k][1] - points[j][1]) * (points[k][1] - points[j][1]);
                        double bb = (points[j][0] - points[i][0]) * (points[j][0] - points[i][0])
                            + (points[j][1] - points[i][1]) * (points[j][1] - points[i][1]);
                        double cc = (points[k][0] - points[i][0]) * (points[k][0] - points[i][0])
                            + (points[k][1] - points[i][1]) * (points[k][1] - points[i][1]);
                        double s = aa * bb - ((aa + bb - cc) / 2) * (aa + bb - cc) / 2;
                        max = Math.max(s, max);
                    }
                }
            }
        }
        return Math.sqrt(max) / 2;
    }

    public static void main(String[] args) {
        Solution_812 model = new Solution_812();
        System.out.println(model.largestTriangleArea(new int[][]{{0, 0}, {0, 1}, {1, 0}, {0, 2}, {2, 0}}));
    }
}
